/***
 * @author lj
 * @绘制接图表格网
 * @type {number[]}
 */
const lngStart2end = [60, 144];
const latStart2end = [0, 60];

var rectangleSource;

function addByZoom(scale) {
    switch (scale) {
        case 100:
            addLine(lnglat_100, "black")
            break;
        case 50:
            addLine(lnglat_50, "black")
            break;
        case 25:
            addLine(lnglat_25, "black")
            break;
        case 10:
            addLine(lnglat_10, "black")
            break;
        case 5:
            addLine(lnglat_5, "black")
            break;
        case 1:
            addLine(lnglat_1, "red")
            break;
    }
}

//绘制格网线
function addLine(lnglat, color) {
    var lng_step = lnglat[0];
    var lat_step = lnglat[1];
    var lineSource = new ol.source.Vector();
    for (var i = lngStart2end[0]; i <= lngStart2end[1]; i += lng_step) {
        var pointslist = [ol.proj.transform([i, latStart2end[0]], "EPSG:4326", "EPSG:3857"),
            ol.proj.transform([i, latStart2end[1]], "EPSG:4326", "EPSG:3857")]
        var line = new ol.geom.LineString(pointslist);
        lineSource.addFeature(new ol.Feature(line));
    }
    for (var i = latStart2end[0]; i <= latStart2end[1]; i += lat_step) {
        var pointslist = [ol.proj.transform([lngStart2end[0], i], "EPSG:4326", "EPSG:3857"),
            ol.proj.transform([lngStart2end[1], i], "EPSG:4326", "EPSG:3857")]
        var line = new ol.geom.LineString(pointslist);
        lineSource.addFeature(new ol.Feature(line))

    }
    var style = new ol.style.Style({
        stroke: new ol.style.Stroke({
            wid: 1,
            color: color
        })
    })
    LineLayer.setStyle(style);
    LineLayer.setZIndex(20);
    LineLayer.setSource(lineSource);
    map.addLayer(LineLayer);
}


//绘制矩形
function addRectangular(sheet,lnglat,color,scale,Vector){

    var xy=Sheet2Num(sheet,scale);

    var point1=xy[0];
    var point2=xy[1];

    var rectangle=new ol.Feature(new ol.geom.Polygon([[[point1[0],point1[1]],[point1[0],point2[1]],[point2[0],point2[1]],[point2[0],point1[1]],[point1[0],point1[1]]]]));
    rectangleSource.addFeature(rectangle);

    var style = new ol.style.Style({
        fill:new ol.style.Fill({
            color:color,
            // opacity:0.5
        })
    })

    Vector.setStyle(style);
    Vector.setZIndex(10);
    Vector.setSource(rectangleSource);
}